class MIMEChecker {
	// create arrays holding the types/codecs support by platform
	private var imageTypes:Array = System.capabilities.imageMIMETypes;
	private var videoTypes:Array = System.capabilities.videoMIMETypes;	
	private var audioTypes:Array = System.capabilities.audioMIMETypes;

	
	// create vars used for checking the MIMEs in three functions
	private var $length:Number;			// for storing the length of MIME arrays
	private var $i:Number;				// for loop conditional
	private var $element:String;			// for storing array pointer value
	private var $match:Boolean;			// boolean for storing if an element equalled passed param
	
	// vars used for getting the MIME type from extension
	private var $index:Number;			// used for storing value of indexOf(".")
	private var $ext:String;				// used for storing the ext of the media being loaded
	
	
	/**
	 * constructor
	 */
	public function MIMEChecker() {
		// nothing	
	}
	
	/**
	 * check for image MIME
	 */
	 public function checkImageType(imageType:String):Boolean {
	 	$length = imageTypes.length;
	 	$i = 0;
	 	while ($i < $length) {
	 		$element = imageTypes[$i];
	 		if (imageType == $element) {
	 			$match = true;
	 		}
	 		$i++;
	 	}
	 	if ($match == true) {
	 		return true;
	 	} else {
	 		return false;
	 	}
	 	delete $length;
	 	delete $i;
	 	delete $element;
	 	delete $match;
	 }
	
	/**
	 * check for video MIME
	 */
	public function checkVideoType(videoType:String):Boolean {
	 	$length = videoTypes.length;
	 	$i = 0;
	 	while ($i < $length) {
	 		$element = videoTypes[$i];
	 		if (videoType == $element) {
	 			$match = true;
	 		}
	 		$i++;
	 	}
	 	if ($match == true) {
	 		return true;
	 	} else {
	 		return false;
	 	}
	 	delete $length;
	 	delete $i;
	 	delete $element;
	 	delete $match;
	 }
	
	/**
	 * check for audio MIME
	 */	
	 public function checkAudioType(soundType:String):Boolean {
	 	$length = audioTypes.length;
	 	$i = 0;
	 	while ($i < $length) {
	 		$element = audioTypes[$i];
	 		if (soundType == $element) {
	 			$match = true;
	 		}
	 		$i++;
	 	}
	 	if ($match == true) {
	 		return true;
	 	} else {
	 		return false;
	 	}
	 	delete $length;
	 	delete $i;
	 	delete $element;
	 	delete $match;
	}
	
	public function getMIME(filePath:String):String {
		$index = filePath.lastIndexOf(".");
		$ext = filePath.substr($index+1);
		
		switch($ext) {
			// extensions for image types
			case "jpg":
				return "image/jpg";
				break;
			case "jpeg":
				return "image/jpg";
				break;
			case "png":
				return "image/png";
				break;
			case "gif":
				return "image/gif";
				break;
			// extensions for video types
			case "mp4":
				return "video/mp4";
				break;
			case "3gp":
				return "video/3gpp";
				break;
			case "3gpp":
				return "video/3gpp";
				break;
			case "mpg":
				return "video/mpg";
				break;
			case "qt":
				return "video/qt";
				break;
			// extensions for audio types
			case "mp3":
				return "audio/mp3";
				break;
			case "aac":
				return "audio/aac";
				break;
			case "qt":
				return "audio/qt";
				break;
			case "ogg":
				return "audio/ogg";
				break;
		}
	}
	
}